<template>
  <div class="home">
    <van-search
      placeholder="商品搜索 共239万款好物"
      input-align="center"
      v-model="searchData"
    />
    <van-swipe :autoplay="3000" :width="375" :height="200">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img class="swiperimg" v-lazy="image.image_url" />
      </van-swipe-item>
    </van-swipe>
    <!-- 五个图标 -->
    <van-grid :column-num="5">
      <van-grid-item
        v-for="(item, index) in channel"
        :key="index"
        :icon="photo-o"
        :text="item.name"
      ></van-grid-item>
    </van-grid>
    <!-- 品牌制造商 -->
    <div class="brandList">
      <van-panel title="品牌制造商直供">
        <van-grid :column-num="2">
          <van-grid-item v-for="(item1, index1) in brandList" :key="index1">
            <van-image fit="cover" lazy-load :src="item1.new_pic_url" />
            <h4 class="title">{{ item1.name }}</h4>
            <p class="price">{{ item1.floor_price }}元起</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
    <!-- 周一周四新品首发 -->
    <div class="newGoodsList">
      <van-panel title="周一周四新品首发">
        <van-grid :column-num="2">
          <van-grid-item v-for="(item2, index2) in newGoodsList" :key="index2">
            <van-image fit="cover" lazy-load :src="item2.list_pic_url" />
            <h4 class="title">{{ item2.name }}</h4>
            <p class="price">{{ item2.retail_price }}元</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
    <!--人气面板-->
    <div class="hotlist">
      <van-panel title="人气推荐">
        <van-card
          v-for="(item3, index3) in hotGoodsList"
          :key="index3"
          :price="item3.retail_price"
          :desc="item3.goods_brief"
          :title="item3.name"
          :thumb="item3.list_pic_url"
        />
      </van-panel>
    </div>
    <div style="height: 50px"></div>
    <!-- footer -->
    <tab-btn></tab-btn>
  </div>
</template>

<script>
// @ is an alias to /src
import axios from "axios";
import api from "../assets/config/api";
import Vue from "vue";
import { Lazyload } from "vant";
import tabBtn from "@/components/comm/tabBtn.vue";

Vue.use(Lazyload);
export default {
  name: "home",
  data: function () {
    return {
      searchData: "",
      data: {},
    };
  },
  async mounted() {
    let res = await axios.get(api.IndexUrl);
    this.data = res.data.data;
  },
  computed: {
    images: function () {
      if (typeof this.data.banner == "object") {
        return this.data.banner;
      } else {
        return [];
      }
    },
    channel: function () {
      if (typeof this.data.channel == "object") {
        return this.data.channel;
      } else {
        return [];
      }
    },
    brandList: function () {
      if (typeof this.data.brandList == "object") {
        return this.data.brandList;
      } else {
        return [];
      }
    },
    newGoodsList: function () {
      if (typeof this.data.newGoodsList == "object") {
        return this.data.newGoodsList;
      } else {
        return [];
      }
    },
    hotGoodsList: function () {
      if (typeof this.data.hotGoodsList == "object") {
        return this.data.hotGoodsList;
      } else {
        return [];
      }
    },
  },

  components: { tabBtn },
};
</script>


<style lang="less" scoped>
.home {
  .van-grid-item {
    overflow: hidden;
  }
  .swiperimg {
    width: 375px;
    height: 200px;
  }
  .brandList {
    position: relative;
    .van-grid-item__content {
      padding: 0;
    }
    .van-image {
      border: 1px solid #fff;
    }
    .title {
      position: absolute;
      top: 20px;
      left: 10px;
    }
    .price {
      position: absolute;
      font-size: 14px;
      top: 40px;
      left: 10px;
      color: #999;
    }
  }
  .newGoodsList {
    .title {
      overflow: hidden;
      white-space: nowrap;
      width: 90%;
      text-overflow: ellipsis;
    }
    .price {
      font-size: 14px;
      color: #999;
      width: 90%;
    }
  }
  .hotlist {
    .van-card__content {
      justify-content: center;
      text-align: left;
    }
    .van-card__title {
      font-weight: 900;
      color: #333;
      font-size: 14px;
      padding: 5px 0;
    }
    .van-card__price {
      color: red;
    }
  }
}
</style>